<html>
<head><meta charset="utf-8"><title>volatile items · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html">volatile items</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="224129557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/224129557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> devsnek <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#224129557">(Jan 27 2021 at 01:33)</a>:</h4>
<p>has anyone ever brought up volatile items? like for example a "volatile array" or a "volatile struct"? i know you could generate a bad version of these using const generics or macros or smth ("bad" since  it would not operate nicely with features like slices and such) but it seems like it could be a nice lang feature for the embedded crowd</p>



<a name="224142231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/224142231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#224142231">(Jan 27 2021 at 05:32)</a>:</h4>
<p>I have, T-lang didn't really go for it. Embedded devs get no love in rust :P</p>



<a name="224692237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/224692237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#224692237">(Feb 01 2021 at 07:16)</a>:</h4>
<p>There are Lang folks, myself included, who would like to see it.</p>



<a name="224692248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/224692248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#224692248">(Feb 01 2021 at 07:16)</a>:</h4>
<p>Needs a precise spec, sufficient to make the formal spec people happy.</p>



<a name="224692399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/224692399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#224692399">(Feb 01 2021 at 07:19)</a>:</h4>
<p>It also needs sufficient clarification to explain how it differs from relaxed atomics.</p>



<a name="227091190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227091190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227091190">(Feb 20 2021 at 13:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/122651-general/topic/volatile.20items/near/224692248">said</a>:</p>
<blockquote>
<p>Needs a precise spec, sufficient to make the formal spec people happy.</p>
</blockquote>
<p>how that? volatile items are just like the <code>Atomic*</code> types, aren't they? they can be built as a library abstraction on top of <code>read/write_volatile</code>. I don't see anything that would have to be specified on the lang level here.</p>



<a name="227091203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227091203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227091203">(Feb 20 2021 at 13:18)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> ^</p>



<a name="227091294"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227091294" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227091294">(Feb 20 2021 at 13:19)</a>:</h4>
<p>That said, there's some half-finished works on replacing <code>read/write_volatile</code> by something more precisely specified; in particular, currently there is no way for a program to request a volatile access that will not tear. But that's a discussion on the level of volatile accesses and thus entirely unrelated to volatile items.</p>



<a name="227091365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227091365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227091365">(Feb 20 2021 at 13:20)</a>:</h4>
<p>Volatile accesses are guaranteed to not tear, right?</p>



<a name="227091427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227091427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227091427">(Feb 20 2021 at 13:21)</a>:</h4>
<p>no. <code>read_volatile</code> works for <code>T</code> of any size, so it's impossible to guarantee no-tear</p>



<a name="227091494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227091494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227091494">(Feb 20 2021 at 13:22)</a>:</h4>
<p>in practice, it's guaranteed to not tear if the access is aligned and "small enough". but this is not properly documented and there's no way for a library to say "make this volatile no-tear or just fail the build" (for cases where tearing would just break everything)</p>



<a name="227091623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227091623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227091623">(Feb 20 2021 at 13:24)</a>:</h4>
<p>I think <a href="https://internals.rust-lang.org/t/add-volatile-operations-to-core-x86-64/10480">https://internals.rust-lang.org/t/add-volatile-operations-to-core-x86-64/10480</a> is the proposal I had in mind</p>



<a name="227091644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227091644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227091644">(Feb 20 2021 at 13:25)</a>:</h4>
<p>but I seem to recall there was another push later by someone else...</p>



<a name="227091658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227091658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227091658">(Feb 20 2021 at 13:25)</a>:</h4>
<p>probably I am thinking of <a href="https://github.com/rust-lang/unsafe-code-guidelines/pull/212">https://github.com/rust-lang/unsafe-code-guidelines/pull/212</a></p>



<a name="227095976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227095976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227095976">(Feb 20 2021 at 14:52)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> one way it could get lang support would be to have a <code>*vol T</code> pointer type which is simply always a volatile access whenever it's used.</p>



<a name="227096103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096103">(Feb 20 2021 at 14:55)</a>:</h4>
<p>If that's all there is to it, why is a library solution not sufficient?</p>



<a name="227096114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096114">(Feb 20 2021 at 14:55)</a>:</h4>
<p>seems like it would be easy enough to make that work with a newtype</p>



<a name="227096179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096179">(Feb 20 2021 at 14:56)</a>:</h4>
<p>i said one way :3</p>
<p>and there are libraries like that, i maintain one of them.</p>
<p>but because they're a library they can't do things like go from a struct to a field of a struct.</p>



<a name="227096269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096269">(Feb 20 2021 at 14:58)</a>:</h4>
<p>at least not ergonomically, you'd have to build a facade type that holds a base address and then  imitates fields with methods that return altered addresses by field type and such.</p>



<a name="227096284"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096284" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096284">(Feb 20 2021 at 14:59)</a>:</h4>
<p>There's still the issue of <code>&amp;T</code> allowing spurious reads</p>



<a name="227096339"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096339" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096339">(Feb 20 2021 at 15:00)</a>:</h4>
<p>Well this has to be a raw pointer in any case</p>



<a name="227096358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096358">(Feb 20 2021 at 15:00)</a>:</h4>
<p>even if <code>*vol T</code> existed it would have to behave basically like <code>*mut T</code></p>



<a name="227096362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096362">(Feb 20 2021 at 15:00)</a>:</h4>
<p>yes that's the idea</p>



<a name="227096392"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096392" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096392">(Feb 20 2021 at 15:01)</a>:</h4>
<p>What is the situation with the raw pointer analogue here? You can't make a raw pointer to a field either</p>



<a name="227096399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096399">(Feb 20 2021 at 15:01)</a>:</h4>
<p>but IIRC there is a macro solution for this</p>



<a name="227096452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096452">(Feb 20 2021 at 15:02)</a>:</h4>
<p>well, correct, because rust is a little behind there too</p>



<a name="227096464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096464">(Feb 20 2021 at 15:02)</a>:</h4>
<p>but it's in Nightly</p>



<a name="227096467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096467">(Feb 20 2021 at 15:02)</a>:</h4>
<p>so perhaps the macro approach can be extended to volatile pointers too</p>



<a name="227096511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096511">(Feb 20 2021 at 15:03)</a>:</h4>
<p>uh, heh, not in a way anyone would want to use</p>



<a name="227096523"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096523" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096523">(Feb 20 2021 at 15:03)</a>:</h4>
<p>that is, you define <code>struct Volatile&lt;T&gt;(*mut T)</code> and then have a macro <code>vol_ref!(x.field)</code> that turns <code>Volatile&lt;Foo&gt;</code> to <code>Volatile&lt;FooField&gt;</code></p>



<a name="227096603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096603">(Feb 20 2021 at 15:04)</a>:</h4>
<p>that would make those portions of a codebase horribly verbose</p>



<a name="227096606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096606">(Feb 20 2021 at 15:05)</a>:</h4>
<p>I think it's a good thing that rust doesn't have volatile variables like C. The notation is way too implicit</p>



<a name="227096635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096635">(Feb 20 2021 at 15:05)</a>:</h4>
<p>Well, are you a person who writes volatile code often?</p>



<a name="227096636"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096636" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096636">(Feb 20 2021 at 15:05)</a>:</h4>
<p>What kind of code needs to use lots of volatiles but can't afford to be explicit about what the accesses are?</p>



<a name="227096651"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096651" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096651">(Feb 20 2021 at 15:06)</a>:</h4>
<p>No, I'm honestly curious</p>



<a name="227096705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096705">(Feb 20 2021 at 15:06)</a>:</h4>
<p>I'm sure there is some application but in all the classic examples like MMIO you want to pack everything behind an API anyway</p>



<a name="227096734"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096734" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096734">(Feb 20 2021 at 15:07)</a>:</h4>
<p>Personally i do not write this particular type of code. i use volatile stuff, but only on a platform with a very simple memory layout, where in fact i have wrapped it all behind an api as you suggest.</p>



<a name="227096744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096744">(Feb 20 2021 at 15:07)</a>:</h4>
<p>for me volatile accesses are basically function calls and they should look like function calls</p>



<a name="227096753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096753">(Feb 20 2021 at 15:07)</a>:</h4>
<p>well then why not function calls for reading a dn writing a reference?</p>



<a name="227096796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096796">(Feb 20 2021 at 15:08)</a>:</h4>
<p>because reading a reference doesn't have side effects</p>



<a name="227096820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096820">(Feb 20 2021 at 15:08)</a>:</h4>
<p>reading a volatile often also doesn't actually have side effects</p>



<a name="227096868"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096868" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096868">(Feb 20 2021 at 15:09)</a>:</h4>
<p>anyway, based on what I've been told, if the mmio address is dynamic then just having "an api for this" becomes quite cumbersome, because as i said you can't easily do fields of a struct</p>



<a name="227096993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227096993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227096993">(Feb 20 2021 at 15:11)</a>:</h4>
<p>What if you only have small scale volatiles, like you would get with <code>VolatileU32</code> style types?</p>



<a name="227097047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227097047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227097047">(Feb 20 2021 at 15:12)</a>:</h4>
<p>so a volatile struct is just a struct with all volatile fields</p>



<a name="227097063"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227097063" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227097063">(Feb 20 2021 at 15:12)</a>:</h4>
<p>I guess this causes problems with volatile enums, since you can get rogue discriminant reads</p>



<a name="227097093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227097093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227097093">(Feb 20 2021 at 15:13)</a>:</h4>
<p>i doubt anyone uses those</p>



<a name="227097185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227097185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227097185">(Feb 20 2021 at 15:14)</a>:</h4>
<p>personally i already have a library that's better than what the language could provide, but i have only limited needs in this area and I'm able to specialize</p>



<a name="227097217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227097217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227097217">(Feb 20 2021 at 15:15)</a>:</h4>
<p>is it on <a href="http://crates.io">crates.io</a>?</p>



<a name="227097305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227097305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227097305">(Feb 20 2021 at 15:17)</a>:</h4>
<p>sorta, the new min_const_generics isn't currently: <a href="https://github.com/rust-console/voladdress/tree/main/src">https://github.com/rust-console/voladdress/tree/main/src</a></p>



<a name="227097437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227097437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227097437">(Feb 20 2021 at 15:19)</a>:</h4>
<p>this version will be the last obvious improvement, so I'm hoping i can boost this to 1.0 if there's no problems in practice</p>



<a name="227097516"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227097516" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227097516">(Feb 20 2021 at 15:20)</a>:</h4>
<p>whoa I've not seen parameterized unsafety before, that's a neat trick</p>



<a name="227097659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227097659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227097659">(Feb 20 2021 at 15:23)</a>:</h4>
<p>it is in fact quite neat, and it's also why the language itself would be unable to match the utility (to me) with a new pointer type.</p>



<a name="227100865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227100865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227100865">(Feb 20 2021 at 16:07)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/122651-general/topic/volatile.20items/near/227095976">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="120791">RalfJ</span> one way it could get lang support would be to have a <code>*vol T</code> pointer type which is simply always a volatile access whenever it's used.</p>
</blockquote>
<p>that would need some lang support, but nothing interesting happens in terms of specifying volatile -- this can be completely explained by lowering down to volatile accesses, it's just some built-in sugar</p>



<a name="227100890"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227100890" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227100890">(Feb 20 2021 at 16:07)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/122651-general/topic/volatile.20items/near/227096464">said</a>:</p>
<blockquote>
<p>but it's in Nightly</p>
</blockquote>
<p>it's stable on nightly actually and thus riding the train to stable :D</p>



<a name="227101272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227101272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227101272">(Feb 20 2021 at 16:13)</a>:</h4>
<p>well volatile doesn't have to be <em>interesting</em> in terms of volatile. I don't think there's anything interesting about it at all. it's quite boring in fact.</p>



<a name="227106312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227106312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Henry-Mantilla <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227106312">(Feb 20 2021 at 17:44)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/122651-general/topic/volatile.20items/near/227097305">said</a>:</p>
<blockquote>
<p>sorta, the new min_const_generics isn't currently: <a href="https://github.com/rust-console/voladdress/tree/main/src">https://github.com/rust-console/voladdress/tree/main/src</a></p>
</blockquote>
<p>FWIW, know that you can get structural equality (to use <code>const</code>ants as patterns) if you use the</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#[derive(PartialEq, Eq)]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">VolAddress_</span><span class="o">&lt;</span><span class="n">Target</span><span class="p">,</span><span class="w"> </span><span class="n">ReadStatus</span><span class="p">,</span><span class="w"> </span><span class="n">WriteStatus</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">pub</span><span class="p">(</span><span class="k">crate</span><span class="p">)</span><span class="w"> </span><span class="n">address</span>: <span class="nc">NonZeroUsize</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="n">target</span>: <span class="nc">Target</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="n">read_status</span>: <span class="nc">ReadStatus</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="n">write_status</span>: <span class="nc">WriteStatus</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">pub</span><span class="w"> </span><span class="k">type</span> <span class="nc">VolAddress</span><span class="o">&lt;</span><span class="n">T</span><span class="p">,</span><span class="w"> </span><span class="n">R</span><span class="p">,</span><span class="w"> </span><span class="n">W</span><span class="o">&gt;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">VolAddress_</span><span class="o">&lt;</span><span class="n">PhantomData</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">PhantomData</span><span class="o">&lt;</span><span class="n">R</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">PhantomData</span><span class="o">&lt;</span><span class="n">W</span><span class="o">&gt;&gt;</span><span class="p">;</span><span class="w"></span>
</code></pre></div>
<p>The main problem then are how it renders in the docs, but you can hide that with some <code>#[cfg(doc)]</code> trickery</p>



<a name="227106547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227106547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227106547">(Feb 20 2021 at 17:48)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/122651-general/topic/volatile.20items/near/227101272">said</a>:</p>
<blockquote>
<p>well volatile doesn't have to be <em>interesting</em> in terms of volatile. I don't think there's anything interesting about it at all. it's quite boring in fact.</p>
</blockquote>
<p>I am just objecting to <span class="user-mention" data-user-id="239881">@Josh Triplett</span>'s claim that there are open questions of semantics around volatile items. You then responded with volatile pointers. If you do not think that those raise questions of semantics then I misunderstood the point you were trying to make.</p>



<a name="227106571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227106571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227106571">(Feb 20 2021 at 17:49)</a>:</h4>
<p>(To be clear, specifying volatile accesses is tricky and I dont think the reference or any other part of the rust [or LLVM] docs does it justice -- but that is entirely orthogonal to whether volatile is considered per-access or per-item/object. My claim here is: volatile items/objects can be entirely specified in terms of volatile accesses, and we already have volatile accesses, so no <em>new</em> spec questions come up from volatile items/objects)</p>



<a name="227108883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227108883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227108883">(Feb 20 2021 at 18:29)</a>:</h4>
<p>I misunderstood the phrase "specified on the lang level" to mean "you would not need language support for" rather than what seems to be your meaning of "you would need to expand the language specification in some way"</p>



<a name="227108968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227108968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227108968">(Feb 20 2021 at 18:30)</a>:</h4>
<p><span class="user-mention" data-user-id="232018">@Daniel Henry-Mantilla</span> you should PR that.</p>



<a name="227109753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227109753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227109753">(Feb 20 2021 at 18:44)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I wasn't necessarily saying that there aren't possible specifications for them, just that <em>if</em> we were going to add them to the language we would need such a spec defining what they do.</p>



<a name="227109864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227109864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227109864">(Feb 20 2021 at 18:46)</a>:</h4>
<p>(And that spec should be self-contained, not "they behave like read_volatile and write_volatile".)</p>



<a name="227109887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227109887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227109887">(Feb 20 2021 at 18:47)</a>:</h4>
<p>It may be that that spec would be easy to supply, and uncontroversial. I'm slightly skeptical that that would be the case, but it's possible.</p>



<a name="227109911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227109911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227109911">(Feb 20 2021 at 18:47)</a>:</h4>
<p>But I think I was primarily echoing your sentiment that specifying them is "tricky".</p>



<a name="227110352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227110352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227110352">(Feb 20 2021 at 18:55)</a>:</h4>
<p>i think they <em>should</em> be specified by referring to something else if possible. that keeps the complexity down. As soon as you understand one thing, you understand both.</p>



<a name="227110527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227110527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227110527">(Feb 20 2021 at 18:58)</a>:</h4>
<p>Particularly, simple syntax sugar explanation is the best.</p>
<p>what we don't want is another unfortunate thing like this:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="o">*</span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Vec</span>::<span class="n">new</span><span class="p">();</span><span class="w"></span>
<span class="n">ptr</span>::<span class="n">write</span><span class="p">(</span><span class="n">x</span><span class="p">,</span><span class="w"> </span><span class="nb">Vec</span>::<span class="n">new</span><span class="p">());</span><span class="w"></span>
</code></pre></div>
<p>where those two lines are slightly different in effect, in a way that a beginner won't really expect.</p>



<a name="227112356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227112356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227112356">(Feb 20 2021 at 19:31)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/122651-general/topic/volatile.20items/near/227109864">said</a>:</p>
<blockquote>
<p>(And that spec should be self-contained, not "they behave like read_volatile and write_volatile".)</p>
</blockquote>
<p>I disagree; it's better to specify this in terms of something lower-level (and already existing!) than trying to reinvent the wheel</p>



<a name="227152457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227152457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227152457">(Feb 21 2021 at 08:21)</a>:</h4>
<p>It feels wrong to specify a language construct in terms of a library function rather than the other way around.</p>



<a name="227152466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227152466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227152466">(Feb 21 2021 at 08:21)</a>:</h4>
<p>isn't it an intrinsic?</p>



<a name="227152539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227152539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mario Carneiro <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227152539">(Feb 21 2021 at 08:22)</a>:</h4>
<p>Not all language features are exposed through special syntax, e.g. UnsafeCell</p>



<a name="227165377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227165377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227165377">(Feb 21 2021 at 12:42)</a>:</h4>
<p>volatile accesses are intrinsics, indeed. so they already are a language construct.</p>



<a name="227165404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/227165404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#227165404">(Feb 21 2021 at 12:42)</a>:</h4>
<p>"the other way around" makes little sense here, that would be explaining volatile accesses in terms of volatile items... but volatile accesses are more expressive since they allow mixing different kinds of accesses on the same location</p>



<a name="241672378"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/241672378" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Demi Obenour <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#241672378">(Jun 06 2021 at 04:40)</a>:</h4>
<p>Volatile is just weird.  For MMIO, I would prefer to have <code>load</code> and <code>store</code> functions that are defined as desugaring to a single machine instruction if possible, or otherwise failing at compile time.</p>



<a name="241694393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/241694393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#241694393">(Jun 06 2021 at 14:26)</a>:</h4>
<p>You could do that on a target by target platform if you wanted.</p>



<a name="241824682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/241824682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gary Guo <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#241824682">(Jun 07 2021 at 19:03)</a>:</h4>
<p>I'll bring this up: <a href="https://www.kernel.org/doc/Documentation/process/volatile-considered-harmful.rst">https://www.kernel.org/doc/Documentation/process/volatile-considered-harmful.rst</a></p>
<p>I don't think it make much sense to have a volatile type. Volatile accesses like <code>read_volatile</code> and <code>write_volatile</code> today is better.</p>



<a name="241855071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/241855071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#241855071">(Jun 07 2021 at 23:39)</a>:</h4>
<p>while that article is not wrong, it's responding to a totally separate problem than we have here.</p>



<a name="241867481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/241867481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Gary Guo <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#241867481">(Jun 08 2021 at 03:40)</a>:</h4>
<p>Sorry, should mention that the references are good read too. Snippet from the second reference of that article:</p>
<blockquote>
<p>In other words, volatile on data structures is _evil_, because it instills<br>
the wrong kind of beliefs in people. "volatility" is not a data structure<br>
issue. It's a matter of the _code_ working on the data structure.</p>
</blockquote>
<p>So the core ideas of the article and its references:</p>
<ol>
<li>Most uses of volatile is wrong</li>
<li>Volatility should not a property of data structure, but rather the code accessing it.</li>
</ol>
<p>In Rust there are even fewer legit use cases of volatile. Is the value shared or exclusive? Volatile does not make sense for the exclusive case, and will be wrong for the shared case. MMIO is probably one of a few use cases, but volatile is still not the full solution here, you still need barriers to access correctly. Volatile aggregates simply don't make sense.</p>



<a name="241921634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/volatile%20items/near/241921634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/volatile.20items.html#241921634">(Jun 08 2021 at 13:47)</a>:</h4>
<p>But I happen to know that Snek <em>wants this for MMIO</em>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>